//
//  WordView.m
//  WordTutor
//
//  Created by lyh on 15/11/18.
//  Copyright © 2015年 lyh. All rights reserved.
//

#import "WordView.h"
#import "CET4WordModel.h"
#import "UILabel+FontSize.h"

@interface WordView ()

@property (nonatomic, strong) UIVisualEffectView *blurView;

@property (nonatomic, strong) UILabel *wordLabel;//放置单词的Label

@property (nonatomic, strong) UILabel *symbolLabel;//放置音标的Label

@property (nonatomic, strong) UILabel *chineseLabel;//放置翻译的Label



@end

@implementation WordView

- (UIVisualEffectView *)blurView
{
    if (!_blurView) {
        CGRect frame = [UIScreen mainScreen].bounds;
        self.blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
        self.blurView.alpha = 0.8f;
        self.blurView.frame = CGRectMake(0, 0, frame.size.width, frame.size.width);
        self.blurView.layer.cornerRadius = frame.size.width/2.0;
        self.blurView.clipsToBounds = YES;
    }
    return _blurView;
}

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.blurView];
        
        //设置放单词的Label
        self.wordLabel = [[UILabel alloc] init];
        self.wordLabel.font = [UIFont systemFontOfSize:20];
        self.wordLabel.textColor = [UIColor magentaColor];
        [self addSubview:self.wordLabel];
        
        //设置放音标的Label
        self.symbolLabel = [[UILabel alloc] init];
        self.symbolLabel.font = [UIFont systemFontOfSize:20];
        [self addSubview:self.symbolLabel];
        
        //设置放翻译的Label
        self.chineseLabel = [[UILabel alloc] init];
        self.chineseLabel.font = [UIFont systemFontOfSize:20];
        [self addSubview:self.chineseLabel];
        
            }
    return self;
}


-(void)updateWordView:(CET4WordModel *)cet4WordModel {
    
    self.wordLabel.text = cet4WordModel.word;
    //获取单词所占
    CGSize wordLabelSize = [self.wordLabel settingSize:self.wordLabel.text];
    self.wordLabel.frame = CGRectMake((self.frame.size.width - wordLabelSize.width) / 2.f, self.frame.size.width / 4.0f - wordLabelSize.height / 2.0f, wordLabelSize.width, wordLabelSize.height);
    
    self.symbolLabel.text = cet4WordModel.symbol;
    CGSize symbolLabelSize = [self.symbolLabel settingSize:self.symbolLabel.text];
    self.symbolLabel.frame = CGRectMake((self.frame.size.width - symbolLabelSize.width) / 2.f, 3 * self.frame.size.width / 4.0f - symbolLabelSize.height / 2.0f, symbolLabelSize.width, symbolLabelSize.height);
//    self.symbolLabel.frame = CGRectMake((self.frame.size.width - symbolLabelSize.width) / 2.f, 2 * self.frame.size.width / 4.0f - wordLabelSize.height / 2.0f, symbolLabelSize.width, symbolLabelSize.height);
    
    self.chineseLabel.text = cet4WordModel.chinese;
    CGSize chineseLabelSize = [self.chineseLabel settingSize:self.chineseLabel.text];
    self.chineseLabel.frame = CGRectMake((self.frame.size.width - chineseLabelSize.width) / 2.f, 2 * self.frame.size.width / 4.0f - chineseLabelSize.height / 2.0f, chineseLabelSize.width, chineseLabelSize.height);
//    self.chineseLabel.frame = CGRectMake((self.frame.size.width - chineseLabelSize.width) / 2.f, 3 * self.frame.size.width / 4.0f - wordLabelSize.height / 2.0f, chineseLabelSize.width, chineseLabelSize.height);
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
